package com.his.dao.jpa;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;

import com.his.pojos.jpa.HisOperationDrug;

public interface MxjOperationDrugDAO extends CrudRepository<HisOperationDrug, Long> {

	@Query("select max(ssypNo) from HisOperationDrug")
	public String findOpDrugMaxId();
	
	@Query("select ssypNo from HisOperationDrug where ssypNo=:ssypNo")
	public String inspectOperationDrugId(@Param("ssypNo")long ssypNo);
	
	@Query("select od from HisOperationDrug od,HisTakedrug td"
			+ " where od.qyNo=td.qyNo and td.ssNo=:ssNo"
			+ " order by od.ssypNo asc")
	public List<HisOperationDrug> findHisOperationDrugByPage(Pageable pageable,@Param("ssNo")BigDecimal ssNo);
	
	@Query("select count(*) from HisOperationDrug od,HisTakedrug td"
			+ " where od.qyNo=td.qyNo and td.ssNo=:ssNo"
			+ " order by od.ssypNo asc")
	public String countss(@Param("ssNo")BigDecimal ssNo);
	
	@Query("select sum(od.cpPrice) from HisOperationDrug od, HisTakedrug td where "
			+ "od.qyNo=td.qyNo and td.ssNo=:ssNo")
	public BigDecimal findpriceByssNo(@Param("ssNo")BigDecimal ssNo);
	
	@Query("select od from HisOperationDrug od,HisTakedrug td"
			+ " where od.qyNo=td.qyNo and td.ssNo=:ssNo and od.cpName=:cpName")
	public HisOperationDrug inspectOperationBysNo(@Param("ssNo")BigDecimal ssNo,@Param("cpName") String cpName);
	
}